package com.leetcode.partition9;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2022/2/27 19:39
 */
public class LC850矩形面积II {

    private static final int N = 1000000010, MOD = 1000000007, M = 410;
    private static SegmentTree root = new SegmentTree(0, N);
    private static Segment[] seg = new Segment[M << 1];

    private static int n = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int n = Integer.parseInt(reader.readLine());
        int[][] rectangles = new int[n][4];
        for (int i = 0; i < n; i++) {
            String[] ss = reader.readLine().split(" ");
            int x1 = Integer.parseInt(ss[0]), y1 = Integer.parseInt(ss[1]), x2 = Integer.parseInt(ss[2]), y2 = Integer.parseInt(ss[3]);
            rectangles[i] = new int[]{x1, y1, x2, y2};
        }
        writer.write(rectangleArea(rectangles) + "\n");
        writer.flush();
    }

    public static int rectangleArea(int[][] rectangles) {
        for (int[] rectangle : rectangles) {
            int x1 = rectangle[0], y1 = rectangle[1], x2 = rectangle[2], y2 = rectangle[3];
            seg[n++] = new Segment(x1, y1, y2, 1);
            seg[n++] = new Segment(x2, y1, y2, -1);
        }
        Arrays.sort(seg, 0, n);
        long ans = 0;
        for (int i = 0; i < n; i++) {
            if (i > 0) ans = (ans + ((long) root.len * (seg[i].x - seg[i - 1].x) % MOD)) % MOD;
            modify(root, seg[i].y1, seg[i].y2 - 1, seg[i].k);
        }
        return (int) (ans % MOD);
    }

    private static void modify(SegmentTree root, int l, int r, int k) {
        if (l <= root.l && r >= root.r) {
            root.cnt += k;
        } else {
            int mid = root.l + root.r >> 1;
            if (l <= mid) modify(root.left(), l, r, k);
            if (r > mid) modify(root.right(), l, r, k);
        }
        pushup(root);
    }

    private static void pushup(SegmentTree root) {
        if (root.cnt > 0) root.len = root.r - root.l + 1;
        else if (root.l == root.r) root.len = 0;
        else root.len = root.left().len + root.right().len;
    }

    private static class Segment implements Comparable<Segment> {
        private int x, y1, y2, k;

        public Segment(int x, int y1, int y2, int k) {
            this.x = x;
            this.y1 = y1;
            this.y2 = y2;
            this.k = k;
        }

        @Override
        public int compareTo(Segment o) {
            return Integer.compare(x, o.x);
        }
    }

    private static class SegmentTree {
        //cnt表示当前区间被覆盖的次数，len表示区间内至少被覆盖一次的长度
        private int l, r, cnt, len;
        private SegmentTree lc, rc;

        public SegmentTree(int l, int r) {
            this.l = l;
            this.r = r;
        }

        public SegmentTree left() {
            if (lc == null) {
                int mid = l + r >> 1;
                lc = new SegmentTree(l, mid);
            }
            return lc;
        }

        public SegmentTree right() {
            if (rc == null) {
                int mid = l + r >> 1;
                rc = new SegmentTree(mid + 1, r);
            }
            return rc;
        }
    }
}
